package it.xiuxian.homepage.presenter

import com.lzy.okgo.OkGo
import it.xiuxian.homepage.activity.QianDaoActivity
import it.xiuxian.homepage.bean.QianDaoBean
import it.xiuxian.homepage.bean.WorkBean
import it.xiuxian.lib.base.BaseBean
import it.xiuxian.lib.base.BasePresenter
import it.xiuxian.lib.base.ILoadBind
import it.xiuxian.lib.bean.NewPersonBean
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.utils.EncodeUtils
import org.json.JSONObject
import java.util.ArrayList

class QianDaoActivityPresenter:BasePresenter<QianDaoActivity>() {
     fun qiandao(){
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL+"/appqiandao/qiandao")
            .execute(object : CallBackOption<BaseBean<String>>() {}.loadBind(mView as QianDaoActivity).execute(
                object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        if(bean.code==0){

                            (mView as QianDaoActivity).updateUI(bean.msg)
                        }
                    }
                }
            ))
    }
    fun getlist(pageNo:String){
        OkGo.post<BaseBean<WorkBean>>(HttpConfig.BASE_URL+"/apprenwu/get")
                .execute(object : CallBackOption<BaseBean<WorkBean>>(){}.loadBind(mView as QianDaoActivity).execute(
                        object : ILoadBind<BaseBean<WorkBean>> {
                            override fun excute(bean: BaseBean<WorkBean>){
                                if(bean.code==0){
                                    var newlist = ArrayList<WorkBean>()
                                    newlist.add(bean.data)
                                    //(mView as QianDaoActivity).setUI(newlist)
                                    (mView as QianDaoActivity).setUI(bean.data)
                                }
                            }
                        }
                ))
    }
    fun getHomePage(){
        OkGo.post<BaseBean<NewPersonBean>>(HttpConfig.BASE_URL+"/appuser/info")
            .execute(object : CallBackOption<BaseBean<NewPersonBean>>() {}.loadBind(mView as QianDaoActivity).execute(
                object :ILoadBind<BaseBean<NewPersonBean>>{
                    override fun excute(bean: BaseBean<NewPersonBean>) {
                        if(bean.code==0){
                            (mView as QianDaoActivity).getXinXI(bean.data)
                        }
                    }
                }
            ))
    }
}